/*
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is ST_EXT-S_UIMAST.
 *
 * The Initial Developer of the Original Code is
 * University of Rome, Tor Vergata
 * Portions created by the Initial Developer are Copyright (C) 2009
 * the Initial Developer. All Rights Reserved.
 */

package it.uniroma2.art.uimast.servlet;

import it.uniroma2.art.ontapi.ARTRepository;
import it.uniroma2.art.ontapi.ARTResource;
import it.uniroma2.art.ontapi.exceptions.VocabularyInitializationException;
import it.uniroma2.art.ontapi.vocabulary.OWL;
import it.uniroma2.art.ontapi.vocabulary.XmlSchema;
import it.uniroma2.art.semanticturkey.resources.Resources;

/**
 * The vocabulary used to manage the corpus. This ontology should belong to the
 * application level of the Semantic Turkey knowledge model. Unfortunately,
 * Semantic Turkey doesn't allow its extensions to register new ontologies, thus
 * the client must initialize the vocabulary before using it. TODO: move this
 * ontology to the application level of the Semantic Turkey knowledge model.
 * 
 * @author <a href="mailto:manuel.fiorelli@gmail.com">Manuel Fiorelli</a>
 * 
 */
public class CorpusVocabulary {
	
	/**
	 * The <code>CorpusVocabulary</code> resources.
	 * 
	 * @author <a href="mailto:manuel.fiorelli@gmail.com">Manuel Fiorelli</a>
	 */
	public static class Res {

		/**
		 * Initializes the <code>CorpusVocabulary</code> resources.
		 * 
		 * @throws VocabularyInitializationException
		 */
		public static void initialize() throws VocabularyInitializationException {
			
			// Avoid multiple initializations.
			if (initialized)
				return;

			try {
				// Gets the ontology repository interface.
				ARTRepository repository = Resources.getRepository();

				// Gets the ann:document class.
				DOCUMENT = repository.getSTClass(CorpusVocabulary.DOCUMENT);
				if (DOCUMENT == null) { // Creates the class, if needed.
					
					repository.addSTSubClass(CorpusVocabulary.DOCUMENT, OWL.Res.THING);
					
					DOCUMENT = repository.getSTClass(CorpusVocabulary.DOCUMENT);
			
				}

				// Gets the ann:language property.
				LANGUAGE = repository.getSTProperty(CorpusVocabulary.LANGUAGE);
				if (LANGUAGE == null) { // Creates the property, if needed.
					
					repository.addProperty(CorpusVocabulary.LANGUAGE, null);
					
					LANGUAGE = repository.getSTProperty(CorpusVocabulary.LANGUAGE);
					
					repository.addPropertyRange(LANGUAGE, repository.createURIResource(XmlSchema.STRING));
				}

				// Gets the ann:uri property.
				URI = repository.getSTProperty(CorpusVocabulary.URI);
				if (URI == null) { // Creates the property, if needed.
					
					repository.addProperty(CorpusVocabulary.URI, null);
					
					URI = repository.getSTProperty(CorpusVocabulary.URI);
					
					repository.addPropertyRange(URI, repository.createURIResource(XmlSchema.STRING));
				}
			} catch (Exception e) { // If an error occurred.
				e.printStackTrace();
				throw new VocabularyInitializationException(
						"Problems occurred in initializing the Corpus ontology vocabulary");
			}

			// Records the initialization
			initialized = true;
		}

		/** The <code>ann:Document</code> class. */
		public static ARTResource DOCUMENT = null;

		/** The <code>ann:language</code> property. */
		public static ARTResource LANGUAGE = null;

		/** The <code>ann:uri</code> property. */
		public static ARTResource URI = null;

		/** A flag denoting if the vocabulary resources were initialized. */
		private static boolean initialized = false;
	}

	/** {@value #DOCUMENT} */
	public static final String DOCUMENT = "http://art.uniroma2.it/ontologies/annotation#Document";

	/** {@value #LANGUAGE} */
	public static final String LANGUAGE = "http://art.uniroma2.it/ontologies/annotation#language";

	/** {@value URI} */
	public static final String URI = "http://art.uniroma2.it/ontologies/annotation#uri";
}
